﻿using System.Linq;
using NHibernate.Validator.Engine;
using TestBat.IModels.Domain;

namespace TestBat.Models.Validators
{
    public class MultipleChoiceTaskSingleCorrectValidator : IValidator
    {
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            IMultipleChoiceTask t = (IMultipleChoiceTask)value;

            if (t.Choices.Count == 0)
                return true;

            return (from c in t.Choices where c.Correct select c).Count<IChoice>() == 1;
        }
    }
}
